package player
{
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;

	public class Player extends Sprite
	{
		private var m_loader:Loader;
		
		public function Player()
		{
			this.x = 300;
			this.y = 200;
			
			m_loader = new Loader;
			m_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoadComplete);
			m_loader.load(new URLRequest("../resource/tianhu.png"));
		}
		
		private function imageLoadComplete(event:Event):void
		{ 
			var widht:int  = m_loader.contentLoaderInfo.width;
			var height:int = m_loader.contentLoaderInfo.height;
			trace("avator width: ", width, "px, height: ", height, "px");
			
			var bitmapData:BitmapData = event.target.content.bitmapData;
			trace("player bitmapdata height: ", bitmapData.height, "px, widht: ", bitmapData.width, "px");
			
			graphics.beginBitmapFill(bitmapData, null, false, true);
			graphics.drawRect(0, 0, bitmapData.width, bitmapData.height); 
			
			m_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, imageLoadComplete);
			m_loader = null;
			
			addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
			addEventListener(MouseEvent.MOUSE_UP, mouseReleased);
		}
		
		private function mouseDown(event:MouseEvent):void
		{
			trace("mouse down");
			startDrag();
			event.stopImmediatePropagation();
		}
		
		private function mouseReleased(event:MouseEvent):void
		{
			trace("mouse up"); 
			stopDrag();
			event.stopImmediatePropagation();
		}
	}
}